﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarInfor.DAL;

namespace CarInfor.UI
{
    public partial class frmSearchByDate : Form
    {

        private int curType;
        public frmSearchByDate()
        {
            InitializeComponent();
            SetEnable(2);
            BindCarType();
        }

        private void rdoCheckDate_CheckedChanged(object sender, EventArgs e)
        {
            SetEnable(1);
        }

        private void rdoExpireDate_CheckedChanged(object sender, EventArgs e)
        {
            SetEnable(2);
        }

        private void rdoCarType_CheckedChanged(object sender, EventArgs e)
        {
            SetEnable(3);
        }

        private void BindCarType()
        {

            this.cboCarType.Items.Clear();
            CarType carType = new CarType();
            DataTable dt = carType.Query();
            this.cboCarType.Items.Add("--请选择--");
            foreach (DataRow row in dt.Rows)
            {
                this.cboCarType.Items.Add(row["类型名称"].ToString());
            }
            this.cboCarType.SelectedIndex = 0;

        }
        void SetEnable(int type)
        {
            switch (type)
            {
                case 1:

                    this.panel1.Enabled = true;
                    this.panel2.Enabled = false;
                    this.cboCarType.Enabled = false;
                    break;
                case 2:
                    this.panel1.Enabled = false;
                    this.panel2.Enabled = true;
                    this.cboCarType.Enabled = false;
                    break;
                case 3:
                    this.panel1.Enabled = false;
                    this.panel2.Enabled = false;
                    this.cboCarType.Enabled = true;
                    break;

            }
            curType = type;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 获取查询字符串
        /// </summary>
        /// <returns></returns>
        public string GetSqlStr()
        {
            string sqlstr = string.Empty;
            switch (curType)
            {
                case 1:
                    sqlstr = " CheckDate between #" + this.dtpChackStartdate.Text + "# and  #" + this.dtpCheckEndDate.Text + "#";
                    break;
                case 2:
                    sqlstr = " ExpireDate between #" + this.dtpExpireStartDate.Text + "# and  #" + this.dtpExpireEndDate.Text + "#";
                    break;
                case 3:
                    sqlstr = " CarType ='" + (this.cboCarType.SelectedItem.ToString().Equals("--请选择--") ? string.Empty : this.cboCarType.SelectedItem.ToString()) + "'";
                    break;
            }
            return sqlstr;

        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }


    }
}
